package com.hxkcloud.patient.activitys;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;



import com.hxkcloud.patient.R;
import com.hxkcloud.patient.aerotel.view.ShowBigPhotoHasTop;
import com.hxkcloud.patient.config.UrlConfig;
import com.hxkcloud.patient.utils.ImageOptionUtils;
import com.hxkcloud.patient.utils.StringUtils;

import java.util.HashMap;


/**
 *
 * Created by songyuequan on 2016/12/20.
 */

public class EcgraphActivtiy extends BaseActivity implements View.OnClickListener {
    public static final String ECGDATA = "ecgData";
    public static final String PATIENTID = "patientId";
    private static final String TAG = EcgraphActivtiy.class.getSimpleName();
    private static final int ADD_REPORT = 1;
    private ImageView iv_ecgraph;
    private TextView tv_time;
    private TextView status;
    private String url;
    private HashMap<String, Object> hdcData;
    Intent lastIntent;
    private TextView tv_title;
    private TextView tv_doctor;
    private ImageView iv_back;
    private LinearLayout ll_title;
    private String patientId;

    private TextView doctor_advice;
    private View line2;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ecg_graph);
        initView();
        initListener();
        lastIntent = getIntent();
        hdcData = (HashMap<String, Object>) lastIntent.getSerializableExtra(ECGDATA);
        patientId = (String) lastIntent.getSerializableExtra(PATIENTID);
        initData();
    }

    @Override
    protected void updateByHandler(Message msg) {

    }

    @Override
    protected void initView() {
        ll_title = (LinearLayout) findViewById(R.id.ll_title);
        iv_back = (ImageView) findViewById(R.id.iv_title_back);
        tv_title = (TextView) findViewById(R.id.tv_title_title);
        tv_doctor = (TextView) findViewById(R.id.tv_doctor);
        line2 =  findViewById(R.id.line2);

        setTitlePadding(ll_title);
        iv_back.setVisibility(View.VISIBLE);
        iv_back.setOnClickListener(this);
        tv_title.setText("心电监测");
        iv_ecgraph = (ImageView) findViewById(R.id.iv_ecgraph);
        tv_time = (TextView) findViewById(R.id.tv_time);
        status = (TextView) findViewById(R.id.name);
        doctor_advice = (TextView) findViewById(R.id.doctor_advice);
    }

    @Override
    protected void initListener() {
        iv_back.setOnClickListener(this);
        iv_ecgraph.setOnClickListener(this);

    }

    protected void initData() {

        if (hdcData == null) {
            return;
        }
        String createTime = (String) hdcData.get("createTime");
        if (createTime != null) {
            tv_time.setText(createTime);
        }
        String diagnose = (String) hdcData.get("diagnose");
        if (diagnose!=null) {
            status.setText("已处理");
            status.setTextColor(Color.parseColor("#7ed321"));
            doctor_advice.setText(diagnose);
            line2.setVisibility(View.VISIBLE);
        } else {
            status.setText("未处理");
            status.setTextColor(Color.parseColor("#ff8744"));
            doctor_advice.setText(null);
            line2.setVisibility(View.GONE);
        }

        String path = (String) hdcData.get("image");
        if (path != null) {
            url = UrlConfig.getHeadUrl() + "upload/" + path;
            Log.i(TAG, url);
            imageLoader.displayImage(url, iv_ecgraph, ImageOptionUtils.getInstance().getSimplePicOptions());
        }

        HashMap<Object,Object> doctorInfo = (HashMap<Object,Object>) hdcData.get("doctorInfo");
        if (doctorInfo!=null){
            String name = (String) doctorInfo.get("name");
            Log.i(TAG,name);
            tv_doctor.setText(name+"    医生");
        }


    }




    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_ecgraph:
                Intent intent = new Intent(mContext, ShowBigPhotoHasTop.class);
                if (!StringUtils.isBlank(url)) {
                    intent.putExtra("url", url);
                }
                startActivity(intent);
                break;
            case R.id.iv_title_back://back
                finish();
                break;
        }
    }
}